
from sqlalchemy import create_engine, Column,String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

Base = declarative_base()

class User(Base):
    __tablename__ = 'user'

    id = Column(String(20), primary_key=True)
    name = Column(String(20))


engin = create_engine("mysql+mysqlconnector://root:lilishop@192.168.3.47:3306/python?charset=utf8")

DBSession = sessionmaker(bind=engin)

#add session对象
# session = DBSession()
#
# new_user = User(id=5, name="thomas")
# session.add(new_user)
# session.commit()
# session.close();


#查询
session = DBSession()
user = session.query(User).filter(User.id=='5').one()
print('type', type(user))
print('name', user.name)
session.close()


